from selenium import webdriver
from selenium.webdriver.common.by import By
import time


def login1(name,password):
    driver = webdriver.Chrome()

    driver.get("http://localhost:90/")

    driver.maximize_window()

    driver.find_element(By.XPATH, '//input[@id="username"]').send_keys(name)
    # 输入账号
    driver.find_element(By.XPATH, '//input[@id="password"]').send_keys(password)
    # 输入密码
    driver.find_element(By.XPATH, '//button[@id="login_btn"]').click()
    # 点击登录按钮
    time.sleep(3)

    return driver


def login2(name, password,info,test_png):
    driver = webdriver.Chrome()

    driver.get("http://localhost:90/")

    driver.maximize_window()

    driver.find_element(By.XPATH,'//input[@id="username"]').send_keys(name)
    # 输入账号
    driver.find_element(By.XPATH,'//input[@id="password"]').send_keys(password)
    # 输入密码
    driver.find_element(By.XPATH,'//button[@id="login_btn"]').click()
    # 点击登录按钮
    time.sleep(3)

    result = driver.find_element(By.XPATH,'//*[@id="logo"]/a').text

    if result == info:
        print("通过")
    else:
        print("不通过！")
        driver.save_screenshot(f"{test_png}.png")

    assert result == info

    driver.quit()


def login3(name,password,info,test_png,args):
    driver = webdriver.Chrome()

    driver.get("http://localhost:90/")

    driver.maximize_window()

    driver.find_element(By.XPATH,'//input[@id="username"]').send_keys(name)

    driver.find_element(By.XPATH,'//input[@id="password"]').send_keys(password)

    driver.find_element(By.XPATH,'//button[@id="login_btn"]').click()

    result = driver.find_element(By.XPATH,f"//div[@class='login-center1']/form/div[{args}]/span[1]").text

    if result == info:
        print('通过!')
    else:
        print('不通过！')
        driver.save_screenshot(f'{test_png}.png')

    assert result == info

    driver.quit()

